package com.cmdi.mq.service.impl;

import com.cmdi.mq.domain.StuStudent;
import com.cmdi.mq.feign.RemoteTeacherClient;
//import io.seata.core.context.RootContext;
//import io.seata.spring.annotation.GlobalTransactional;
//import io.swagger.models.auth.In;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SeataTestServiceImpl {
    @Autowired
    private StuStudentService studentService;
    @Autowired
    private RemoteTeacherClient remoteTeacherClient;

    //@GlobalTransactional(rollbackFor = Exception.class)
    //@Transactional(rollbackFor = Exception.class)
    @Trace
    @Tags({
            @Tag(key = "test.a", value = "arg[0]"),
            @Tag(key = "test.b", value = "arg[1]"),
            @Tag(key = "test.c", value = "arg[2]"),
            @Tag(key = "returnValue", value = "returnedObj")
    })
    public int test(int a, int b, int c) {

        remoteTeacherClient.teaA("" + c);

        StuStudent e = new StuStudent();
        e.setPassword(c + "");
        e.setStatus(new Integer(c).byteValue());
        boolean i = studentService.save(e);
        System.out.println("save? " + i);
        //System.out.println(RootContext.getXID());
        try {
            Thread.sleep(2000);
        } catch (InterruptedException interruptedException) {
            interruptedException.printStackTrace();
        }
        System.out.println(a / b);
        return a / b;

    }
}
